const Router = require('koa-router')
const router = new Router({ prefix: '/user' })

// 引入数据库方法
const service = require('../service/user_service')

// 用户注册
router.post('/register', async (ctx, next) => {
  const user = ctx.request.body
  const { message, status } = await service.register(user)
  ctx.status = status
  console.log(message);
  ctx.body = message
})
// 用户登录
router.post('/login', async (ctx, next) => {
  const user = ctx.request.body
  const { message, status, token, userInfo } = await service.login(user)
  ctx.status = status
  ctx.body = {
    message,
    token,
    userInfo
  }
})

module.exports = router